from flask import Flask
from flask_uploads import configure_uploads
from flask_uploads import UploadSet, IMAGES, DOCUMENTS, ARCHIVES, AUDIO

# 定义允许的文件类型
ALLOWED_EXTENSIONS = {
    # 图片格式
    'images': ('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp', 'svg', 'ico'),
    # 文档格式
    'documents': ('pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf'),
    # 压缩文件
    'archives': ('zip', 'rar', '7z', 'tar', 'gz'),
    # 音频格式
    'audio': ('mp3', 'wav', 'flac', 'aac', 'ogg', 'wma'),
    # 视频格式
    'video': ('mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'webm'),
    # 附件格式（包含所有文档和压缩文件）
    'attachment': ('pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf', 'zip', 'rar', '7z', 'tar', 'gz'),
    # 其他文件
    'others': ('csv', 'json', 'xml', 'html', 'css', 'js')
}

# 创建不同的上传集合
photos = UploadSet('photos', ALLOWED_EXTENSIONS['images'])
documents = UploadSet('documents', ALLOWED_EXTENSIONS['documents'])
archives = UploadSet('archives', ALLOWED_EXTENSIONS['archives'])
audio = UploadSet('audio', ALLOWED_EXTENSIONS['audio'])
video = UploadSet('video', ALLOWED_EXTENSIONS['video'])  # 自定义视频类型
attachment = UploadSet('attachment', ALLOWED_EXTENSIONS['attachment'])  # 附件类型
others = UploadSet('others', ALLOWED_EXTENSIONS['others'])

# 创建通用上传集合（包含所有允许的文件类型）
allfiles = UploadSet('allfiles', 
    ALLOWED_EXTENSIONS['images'] + 
    ALLOWED_EXTENSIONS['documents'] + 
    ALLOWED_EXTENSIONS['archives'] + 
    ALLOWED_EXTENSIONS['audio'] + 
    ALLOWED_EXTENSIONS['video'] + 
    ALLOWED_EXTENSIONS['others']
)
from .decorator.ext_decorator import ext_decorator
@ext_decorator
def init_upload(app: Flask):
    # 配置所有上传集合
    configure_uploads(app, (photos, documents, archives, audio, video, attachment, others, allfiles))
